home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / borland / prbgi097.zip / C.ZIP / OUTMSG.C < prev    next >
C/C++ Source or Header  |  1992-12-15  |  3KB  |  81 lines

  1. #include "graphics.h"
  2. #include "outmsg.h"
  3. #include <alloc.h>
  4.  
  5. struct imageBuf { int x1,y1,x2,y2;
  6.                   char buf[2];
  7.                 };
  8.  
  9. /*=================================================================*/
  10. void  far pascal Outmsg( const char far *msg1, const char far *msg2,
  11.                          void far* far* imagePtr )
  12. /*=================================================================*/
  13. /* This procedure displays on graphic screen two lines with
  14.     msg1 and msg2 texts respectivly.
  15.     If imagePtr is not NIL it also allocates memory and saves
  16.     overwitten part of screen in that memory. Pointer to allocated
  17.     memory is returned in *imagePtr variable. You may use CloseOutMsg
  18.     procedure to restore screen contents and free the memory
  19.  */
  20. {
  21.    int   h,w,x1,y1,x2,y2;
  22.    struct textsettingstype ts;
  23.    struct viewporttype     vp;
  24.  
  25.    gettextsettings(&ts);
  26.    getviewsettings(&vp);
  27.  
  28.    settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
  29.    settextjustify(CENTER_TEXT,TOP_TEXT);
  30.    h=textheight(msg1);
  31.    w=textwidth(msg1);
  32.    if ( h<textheight(msg2) ) h=textheight(msg2);
  33.    if ( w<textwidth(msg2) ) w=textwidth(msg2);
  34.    h +=15;
  35.    w +=16;
  36.    x1=(getmaxx()-w)/2-8; y1=getmaxy()/2-h-8;
  37.    x2=(getmaxx()+w)/2+8; y2=getmaxy()/2+h+8;
  38.    if ( imagePtr!=NULL )
  39.    {  struct imageBuf  far *p;
  40.       unsigned   s;
  41.       *imagePtr=NULL;
  42.       if ( (s=imagesize(x1,y1,x2,y2)) < 0xfff0 )
  43.       {
  44.          if ( (p=(struct imageBuf*)farmalloc(s+8))!=NULL )
  45.          {
  46.             getimage(x1,y1,x2,y2,p->buf);
  47.             p->x1=x1; p->y1=y1;
  48.             p->x2=x2; p->y2=y2;
  49.             *imagePtr=p;
  50.          }
  51.       }
  52.    }
  53.    setviewport( x1,y1, x2, y2, 1);
  54.    setcolor(getmaxcolor());
  55.    setfillstyle(SOLID_FILL,BLACK);
  56.    clearviewport(); // bar(0,0,w,2*h);
  57.    rectangle(0,0,w+16,2*h+16);
  58.    setviewport( x1+8,y1+8, x2-8, y2-8, 1);
  59.    rectangle(0,0,w,2*h);
  60.    outtextxy(w/2,5, msg1);
  61.    outtextxy(w/2,10+h, msg2);
  62.  
  63.    settextstyle(ts.font,ts.direction,ts.charsize);
  64.    settextjustify(ts.horiz,ts.vert);
  65.    setviewport(vp.left,vp.top, vp.right,vp.bottom, vp.clip);
  66. }
  67.  
  68. /*=====================================================*/
  69. void  far pascal CloseOutmsg( void far* far* imagePtr )
  70. /*=====================================================*/
  71. {
  72.    if ( imagePtr!=NULL && *imagePtr!=NULL )
  73.    {  struct imageBuf  far *p;
  74.       p=(struct imageBuf*)*imagePtr;
  75.       putimage(p->x1,p->y1,p->buf,COPY_PUT);
  76.       farfree(p);
  77.       *imagePtr=NULL;
  78.    }
  79. }
  80.  
  81.